//
//  WBPhotoCollectionCell.m
//  sinaWeibo
//
//  Created by 李江波 on 2016/11/23.
//  Copyright © 2016年 lijiangbo. All rights reserved.
//

#import "WBPhotoCollectionCell.h"
#import <Masonry.h>

@interface WBPhotoCollectionCell ()

@property(nonatomic ,weak) UIButton *btn;

@property(nonatomic ,strong) UIButton *removeBtn;
@end

@implementation WBPhotoCollectionCell

-(instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    
    return self;
}

-(void)setupUI{

    UIButton *btn = [UIButton buttonWithType:0];
    _removeBtn = [UIButton buttonWithType:0];
    
    _btn = btn;
    
    btn.imageView.contentMode = UIViewContentModeScaleAspectFill;
    [btn setBackgroundImage:[UIImage imageNamed:@"compose_pic_add"] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"compose_pic_add_highlighted"] forState:UIControlStateNormal];
    
    [_removeBtn setImage:[UIImage imageNamed:@"compose_photo_close"] forState:UIControlStateNormal];
    
    [self.contentView addSubview:btn];
    [self.contentView addSubview:_removeBtn];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [_removeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.equalTo(self);
    }];
    
    //增加点击
    
    [btn addTarget:self action:@selector(addBtnClick) forControlEvents:UIControlEventTouchUpInside];
    //删除点击
    [_removeBtn addTarget:self action:@selector(removeBtnClick) forControlEvents:UIControlEventTouchUpInside];
}

-(void)setImage:(UIImage *)image{

    _image = image;
    [_btn setImage:image forState:UIControlStateNormal];
    
    self.removeBtn.hidden = image == nil;
}


-(void)addBtnClick{
    
    if (self.image != nil) {
        NSLog(@"已经有图片了呢");
        return;
    }

    if ([self.delegate respondsToSelector:@selector(photoChooseAddClick:)]) {
        
        [self.delegate photoChooseAddClick:self];
    }
    
}

-(void)removeBtnClick{

    if ([self.delegate respondsToSelector:@selector(photoChooseRemoveClick:)]) {
        
        [self.delegate photoChooseRemoveClick:self];
    }
    
}


@end







